package com.mudrov.internetdownloader;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;

public class Executor {

    private static Logger logger = Logger.getLogger(Executor.class);

    public static void main(String[] args){
        if (args.length != 1) {
            logger.log(Level.FATAL,"Incorrect parameters!");
            return;
        }
        Properties properties = new Properties();
        try {
            properties.load(Executor.class.getClassLoader().getResourceAsStream(Parameters.PROP_FILE_NAME.value()));
            int depth = Integer.parseInt(properties.getProperty(Parameters.MAX_DEPTH.value()));
            Reactor.downloadAllPages(new URL(args[0].startsWith("http://") ? args[0] : "http://" + args[0]), depth);
        } catch (MalformedURLException e) {
            logger.log(Level.FATAL,"Can`t parse URL.");
        } catch (IOException e) {
            File f = new File("");
            logger.log(Level.FATAL,"Can`t load file with properties.");
        }
    }
}
